/*
 * MainFrame.cpp
 *
 *  Created on: 2012-8-28
 *      Author: yangentao@gmail.com
 */
#include "window.h"
#include "MainFrame.h"

namespace ui {

const LPCTSTR MainFrame::MainFrameClassName = TEXT("__MainFrameClassName__");

WindowClass MainFrame::winClass;

int MainFrame::mainFrameCount = 0;

MainFrame::MainFrame() {

	if (!winClass.isRegistered()) {
		winClass.createClass(MainFrameClassName);
		winClass.registerClass();
	}
}

MainFrame::~MainFrame() {

}

bool MainFrame::create(LPCTSTR title, int x, int y, int width, int height) {
	return create(title, Rect(x, y, x + width, y + height));
}
bool MainFrame::create(LPCTSTR title, Rect rect) {
	++mainFrameCount;
	DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;
	DWORD exStyle = WS_EX_APPWINDOW | WS_EX_ACCEPTFILES;
	return Super::create(MainFrameClassName, title, style, exStyle, rect, 0);
}

void MainFrame::fireOnFinished(HWND w) {
	Super::fireOnFinished(w);
	--mainFrameCount;
	if(!mainFrameCount){
		::PostQuitMessage(0);
	}
}

} /* namespace ui */
